class PatientIDGenerator:
    """
    用于生成连续的 patient_id，例如 PT1001, PT1002 ...
    """
    def __init__(self, prefix="PT", start=10001):
        self.prefix = prefix
        self.start = start  # 起始数字
        self.current = None  # 当前数字，None表示还没生成过

    def next_id(self, reset=False):
        """
        生成下一个 patient_id
        :param reset: True 重置计数器，False 继续上一次
        :return: patient_id 字符串
        """
        if reset or self.current is None:
            self.current = self.start
        else:
            self.current += 1
        return f"{self.prefix}{self.current}"

    def set_current(self, number):
        """
        手动设置当前数字
        """
        self.current = number

    def reset(self, start=None):
        """
        重置计数器
        """
        if start is not None:
            self.start = start
        self.current = None
